package xyz.msj.hrm.feign.client;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import xyz.msj.hrm.feign.fallback.RedisFeignClientFallbackFactory;
import xyz.msj.hrm.util.AjaxResult;

import java.util.List;

@Component
//用来调用 cache-server 微服务的feign接口
@FeignClient(value = "cache-server",fallbackFactory = RedisFeignClientFallbackFactory.class ) //
public interface RedisFeignClient {

    /**
     * 设置值
     * http://localhost:1070/redis/set?key=username&value=123
     * @RequestParam  获取地址上面对象的值
     */
    @PostMapping("/redis/set")
    AjaxResult set(@RequestParam String key, @RequestParam String value) ;

    @PostMapping("/redis/setex")
    AjaxResult setex(@RequestParam String key, @RequestParam int seconds, @RequestParam String value);

    /**
     * 获取值
     * http://localhost:1070/redis/get/key
     * @RequestParam  获取地址上面对象的值
     */
    @GetMapping("/redis/get/{key}")
     AjaxResult get(@PathVariable("key") String key) ;


    /**
     * 删除值
     * http://localhost:1070/redis/del/key
     * @RequestParam  获取地址上面对象的值
     */
    @DeleteMapping("/redis/del/{key}")
    AjaxResult del(@PathVariable("key") String key) ;

    /**
     * hash 存储值
     * http://localhost:1070/redis/set?key=username&value=123
     *
     * @RequestParam 获取地址上面对象的值
     */
    @PostMapping("/redis/hset")
    AjaxResult hset(@RequestParam String key, @RequestParam String filed, @RequestParam byte[] value);

    /**
     * hash 获取值
     * http://localhost:1070/redis/set?key=username&value=123
     *
     * @RequestParam 获取地址上面对象的值
     */
    @PostMapping("/redis/hget")
    AjaxResult hget(@RequestParam String key, @RequestParam String filed);

    /**
     * hash 获取所有值
     * http://localhost:1070/redis/set?key=username&value=123
     *
     * @RequestParam 获取地址上面对象的值
     */
    @PostMapping("/redis/hvals")
    List<byte[]> hvals(@RequestParam String key);

}
